/**
 * Copyright(C)2012-2013 深圳市掌星立意科技有限公司版权所有
 * 创 建 人:Jacky
 * 修 改 人:
 * 创 建日期:2013-7-25
 * 描    述:xml储存数据
 * 版 本 号:
 */
package com.szbber.door.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.szbber.door.R;
import com.szbber.door.base.BaseApplication;


public final class PreferUtil {

    private static Context context;

    public static PreferUtil INSTANCE;
    private static SharedPreferences mPrefer;
    private static final String APP_NAME = "com.jzr.bedside";


    private static final String SERVICEIP = "ServiceIp";
    private static final String SERVERPORT = "ServerPort";

    private static final  String SOCKETIP="SocketIp";

    private static final String DEPTCODE = "deptCode";
    private static final String DEPTNAME = "deptName";

    private static final String BEDCODE = "bedCode";
    private static final String BEDNAME = "bedName";
    private static final  String PATIENTID ="patientId";

    private  static  final  String USERID="userId";

    public void setSocketip(String fag){
        putString(SOCKETIP,fag);
    }

    public  String getSocketip()
    {
        return  getString(SOCKETIP,"");
    }


    public void setPatientId(String fag){
        putString(PATIENTID,fag);
    }

    public  String getPatientId(){
        return  getString(PATIENTID,"");
    }

    public void setUserId(String fag){
        putString(USERID,fag);
    }

    public  String getUserId(){
        return  getString(USERID,"");
    }



    public  void  setBedName(String fag){
        putString(BEDNAME, fag);
    }

    public  String getBedName(){
        return getString(BEDNAME,"");
    }


    public  void  setBedCode(String fag){
        putString(BEDCODE, fag);
    }

    public  String getBedCode(){
        return getString(BEDCODE,"");
    }



    public  void  setDeptName(String fag){
        putString(DEPTNAME, fag);
    }

    public  String getDeptName(){
        return getString(DEPTNAME,"");
    }

    public  void  setDeptCode(String fag){
        putString(DEPTCODE, fag);
    }

    public  String getDeptCode(){
        return getString(DEPTCODE,"");
    }


    public void setServiceIp(String fag) {
        putString(SERVICEIP, fag);
    }

    public String getServiceIp() {
        return getString(SERVICEIP, BaseApplication.Companion.getContext().getResources().getString(R.string.serviceIp));
    }

    public void setServerPort(String fag) {
        putString(SERVERPORT, fag);
    }

    public String getServerPort() {
        return getString(SERVERPORT, BaseApplication.Companion.getContext().getResources().getString(R.string.servicePort));
    }


    private PreferUtil() {

    }

    public static PreferUtil getInstance() {
        if (INSTANCE == null) {
            context = BaseApplication.Companion.getContext();
            return new PreferUtil();
        }
        return INSTANCE;
    }

    public void init(Context ctx) {
        mPrefer = ctx.getSharedPreferences(APP_NAME, Context.MODE_PRIVATE
                | Context.MODE_PRIVATE);
        mPrefer.edit().commit();
    }

    public String getString(String key, String defValue) {
        return mPrefer.getString(key, defValue);
    }

    public int getInt(String key, int defValue) {
        return mPrefer.getInt(key, defValue);
    }

    public boolean getBoolean(String key, boolean defValue) {
        return mPrefer.getBoolean(key, defValue);
    }

    public void putString(String key, String value) {
        mPrefer.edit().putString(key, value).commit();
    }

    public void putInt(String key, int value) {
        mPrefer.edit().putInt(key, value).commit();
    }

    public void putBoolean(String key, boolean value) {
        mPrefer.edit().putBoolean(key, value).commit();
    }

    public void putLong(String key, long value) {
        mPrefer.edit().putLong(key, value).commit();
    }

    public long getLong(String key, long defValue) {
        return mPrefer.getLong(key, defValue);
    }

    public void removeKey(String key) {
        mPrefer.edit().remove(key).commit();
    }


}
